package simple.demo.springintegration.demo.chapter5;

import java.util.Date;
import java.util.Random;
import java.util.concurrent.TimeUnit;

import org.springframework.integration.Message;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.integration.support.MessageBuilder;

public class SimpleDelayedHandler {

	void log(Object msg) {
		System.out.println(new Date() + " - " + msg);		
	}
	
	@ServiceActivator
	public Message<Object> justDelay(Message<Object> obj) throws Exception {
		int wait = new Random().nextInt(1000);
		log(obj.getPayload() + " : Delays in thread " + Thread.currentThread().getId() + " for " + wait + " millisecs.");
		TimeUnit.MILLISECONDS.sleep(wait);
		log(obj.getPayload() + " : Ends Delaying in thread " + Thread.currentThread().getId());
		return obj;
	}
}
